﻿//======================================================================
//
//        Copyright (C) 苏州逸仙软件    
//        All rights reserved
//
//        filename : D_PowerGroupSonExp.cs
//        description :
//
//        created by 周济 at 2010/8/22 16:22:08
//        mail:13912699233@139.com
//
//======================================================================


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace ksyx.User.Dal
{
    public class D_PowerGroupSonExp : D_PowerGroupSon
    {
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool ExistsExp(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_PowerGroupSon");
            strSql.Append(" where id=@id and flag=1  ");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)};
            parameters[0].Value = id;

            return ksyx.DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddExp(ksyx.User.Model.T_PowerGroupSon model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_PowerGroupSon(");
            strSql.Append("PowerGroupID,UserID,Flag)");
            strSql.Append(" values (");
            strSql.Append("@PowerGroupID,@UserID,1)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@PowerGroupID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@Flag", SqlDbType.Bit,1)};
            parameters[0].Value = model.PowerGroupID;
            parameters[1].Value = model.UserID;
            parameters[2].Value = model.Flag;

            object obj = ksyx.DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int UpdateExp(ksyx.User.Model.T_PowerGroupSon model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_PowerGroupSon set ");
            strSql.Append("PowerGroupID=@PowerGroupID,");
            strSql.Append("UserID=@UserID,");
            strSql.Append("Flag=Flag");
            strSql.Append(" where id=@id ");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4),
					new SqlParameter("@PowerGroupID", SqlDbType.Int,4),
					new SqlParameter("@UserID", SqlDbType.Int,4),
					new SqlParameter("@Flag", SqlDbType.Bit,1)};
            parameters[0].Value = model.id;
            parameters[1].Value = model.PowerGroupID;
            parameters[2].Value = model.UserID;
            parameters[3].Value = model.Flag;

            return ksyx.DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        public int DelExp(int id) 
        {
            return " T_PowerGroupSon ".Exp_UpdateFlag(id, YXSQL.SQLConType.C1);
        }
    }
}
